package test;

import static org.junit.Assert.assertTrue;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import expression.PostfixEvaluator;

public class AmandaWebsterPETest {

	@Before
	public void setUp() throws Exception {
	}

	@After
	public void tearDown() throws Exception {
	}

	@Test
	public void additionTest() {
		int answer = PostfixEvaluator.eval("1 4 +");
		assertTrue(answer == 5);
		
		answer = PostfixEvaluator.eval("  1        4    +   ");
		assertTrue(answer == 5);

		answer = PostfixEvaluator.eval("5 7 1 2 4 8 23 18 24 + + + + + + + +");
		assertTrue(answer == 92);
		
		answer = PostfixEvaluator.eval("  5      7 1 2      4     8 23      18  24 + +      +    + + +     +  +  ");
		assertTrue(answer == 92); 
	}
	
	@Test
	public void subtractionTest() {
		int answer = PostfixEvaluator.eval("1 4 -");
		assertTrue(answer == -3);
		
		answer = PostfixEvaluator.eval("1        4    -   ");
		assertTrue(answer == -3);

		 answer = PostfixEvaluator.eval("3 7 * 5 -");
		assertTrue(answer == 16);
		
		answer = PostfixEvaluator.eval("    3 7       * 5 -");
		assertTrue(answer == 16);
	}
	
	@Test
	public void multiplicationTest() {
		
		int answer = PostfixEvaluator.eval("3 8 9 2 5 * * * *");
		assertTrue(answer == 2160);
		
		answer = PostfixEvaluator.eval("3 1 2 * *");
		assertTrue(answer == 6);
		
	}
	
	@Test
	public void divisionTest() {
		int answer = PostfixEvaluator.eval("4 2 /");
		assertTrue(answer == 2);
		
		answer = PostfixEvaluator.eval("3 2 * 2 /");
		assertTrue(answer == 3);
		
		answer = PostfixEvaluator.eval("4 3 /");
		assertTrue(answer == 1);
		
		answer = PostfixEvaluator.eval("7 2 /");
		assertTrue(answer == 3);
	}
	
	@Test
	public void exponentTest() {
		int answer = PostfixEvaluator.eval("2 2 ^");
		assertTrue(answer == 4);
		
		answer = PostfixEvaluator.eval("6 3 ^");
		assertTrue(answer == 216);
		
		answer = PostfixEvaluator.eval("12 6 ^");
		assertTrue(answer == 2985984);
		
		answer = PostfixEvaluator.eval("3 13 ^");
		assertTrue(answer == 1594323);
		
		answer = PostfixEvaluator.eval("2 7 ^");
		assertTrue(answer == 128);
		
		answer = PostfixEvaluator.eval("8 2 ^");
		assertTrue(answer == 64);
	}
}















